﻿using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Neovolve.Extensibility.VisualStudio.TestProfilerLink.UnitTests
{
    /// <summary>
    ///This is a test class for TestFrameworkConfigurationExceptionTests and is intended
    ///to contain all TestFrameworkConfigurationExceptionTests Unit Tests
    ///</summary>
    [TestClass]
    public class TestFrameworkConfigurationExceptionTests
    {
        /// <summary>
        ///A test for FrameworkName
        ///</summary>
        [TestMethod]
        [DeploymentItem("Neovolve.Extensibility.VisualStudio.TestProfilerLink.dll")]
        public void FrameworkNameTest()
        {
            TestFrameworkConfigurationException_Accessor target = new TestFrameworkConfigurationException_Accessor();
            String expected = Guid.NewGuid().ToString();

            target.FrameworkName = expected;

            String actual = target.FrameworkName;

            Assert.AreEqual(expected, actual, "FrameworkName returned an incorrect value.");
        }

        /// <summary>
        ///A test for Message
        ///</summary>
        [TestMethod]
        public void MessageFrameworkNamePropertyNameTest()
        {
            String frameworkName = Guid.NewGuid().ToString();
            String propertyName = Guid.NewGuid().ToString();
            TestFrameworkConfigurationException target = new TestFrameworkConfigurationException(
                frameworkName, propertyName);

            String actual = target.Message;

            Assert.IsFalse(String.IsNullOrEmpty(actual), "Message returned an incorrect value.");
            Assert.IsTrue(actual.Contains(frameworkName), "Message returned did not contain the framework name.");
            Assert.IsTrue(actual.Contains(propertyName), "Message returned did not contain the property name.");
        }

        /// <summary>
        ///A test for Message
        ///</summary>
        [TestMethod]
        public void MessageTest()
        {
            String expected = Guid.NewGuid().ToString();
            TestFrameworkConfigurationException target = new TestFrameworkConfigurationException(expected);
            String actual = target.Message;

            Assert.AreEqual(expected, actual, "Message returned an incorrect value.");
        }

        /// <summary>
        ///A test for PropertyName
        ///</summary>
        [TestMethod]
        [DeploymentItem("Neovolve.Extensibility.VisualStudio.TestProfilerLink.dll")]
        public void PropertyNameTest()
        {
            String expected = Guid.NewGuid().ToString();
            TestFrameworkConfigurationException_Accessor target = new TestFrameworkConfigurationException_Accessor();
            target.PropertyName = expected;

            String actual = target.PropertyName;

            Assert.AreEqual(expected, actual, "PropertyName returned an incorrect value.");
        }

        /// <summary>
        ///A test for TestFrameworkConfigurationException Constructor
        ///</summary>
        [TestMethod]
        public void TestFrameworkConfigurationExceptionConstructorFrameworkNamePropertyNameTest()
        {
            String frameworkName = Guid.NewGuid().ToString();
            String propertyName = Guid.NewGuid().ToString();
            TestFrameworkConfigurationException target = new TestFrameworkConfigurationException(
                frameworkName, propertyName);

            String actual = target.Message;

            Assert.IsFalse(String.IsNullOrEmpty(actual), "Message returned an incorrect value.");
            Assert.IsTrue(actual.Contains(frameworkName), "Message returned did not contain the framework name.");
            Assert.IsTrue(actual.Contains(propertyName), "Message returned did not contain the property name.");
            Assert.AreEqual(frameworkName, target.FrameworkName, "FrameworkName returned an incorrect value.");
            Assert.AreEqual(propertyName, target.PropertyName, "PropertyName returned an incorrect value.");
        }

        /// <summary>
        ///A test for TestFrameworkConfigurationException Constructor
        ///</summary>
        [TestMethod]
        public void TestFrameworkConfigurationExceptionConstructorMessageExceptionTest()
        {
            String message = Guid.NewGuid().ToString();
            Exception inner = new SystemException();
            TestFrameworkConfigurationException target = new TestFrameworkConfigurationException(message, inner);

            Assert.AreEqual(message, target.Message, "Message returned an incorrect value.");
            Assert.IsTrue(String.IsNullOrEmpty(target.FrameworkName), "FrameworkName returned an incorrect value.");
            Assert.IsTrue(String.IsNullOrEmpty(target.PropertyName), "PropertyName returned an incorrect value.");
            Assert.AreEqual(inner, target.InnerException, "InnerException returned an incorrect value.");
        }

        /// <summary>
        ///A test for TestFrameworkConfigurationException Constructor
        ///</summary>
        [TestMethod]
        public void TestFrameworkConfigurationExceptionConstructorMessageTest()
        {
            String message = Guid.NewGuid().ToString();
            TestFrameworkConfigurationException target = new TestFrameworkConfigurationException(message);

            Assert.AreEqual(message, target.Message, "Message returned an incorrect value.");
        }

        /// <summary>
        ///A test for TestFrameworkConfigurationException Constructor
        ///</summary>
        [TestMethod]
        [DeploymentItem("Neovolve.Extensibility.VisualStudio.TestProfilerLink.dll")]
        public void TestFrameworkConfigurationExceptionConstructorSerializationTest()
        {
            const String ExceptionMessage = "Adapter Test Message";
            TestFrameworkConfigurationException target = new TestFrameworkConfigurationException(ExceptionMessage);

            MemoryStream ms = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(ms, target);
            ms.Seek(0, SeekOrigin.Begin);
            TestFrameworkConfigurationException outputException =
                formatter.Deserialize(ms) as TestFrameworkConfigurationException;

            Assert.IsNotNull(outputException, "Failed to serialize and deserialize the exception.");
            Assert.AreEqual(ExceptionMessage, outputException.Message, "Message returned an incorrect value.");
        }

        /// <summary>
        ///A test for TestFrameworkConfigurationException Constructor
        ///</summary>
        [TestMethod]
        public void TestFrameworkConfigurationExceptionConstructorTest()
        {
            TestFrameworkConfigurationException target = new TestFrameworkConfigurationException();

            Assert.IsFalse(String.IsNullOrEmpty(target.Message), "Message returned an incorrect value.");
        }

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get;
            set;
        }
    }
}